package com.rykj.energy.task.api.rest;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rykj.energy.common.utils.Result;
import com.rykj.energy.database.pojo.vo.MsgParamVo;
import com.rykj.energy.database.pojo.vo.MsgResultVo;
import com.rykj.energy.database.service.IMsgResultService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "报警消息管理")
@Slf4j
@RestController
@RequestMapping("/msgResult")
public class MsgResultController {

    @Autowired
    private IMsgResultService msgResultService;

    @ApiOperation("报警消息查询")
    @PostMapping("/findMessages/{pageNum}/{pageSize}")
    public Result<IPage<MsgResultVo>> findMessages(@PathVariable("pageNum")Integer pageNum,
                                                   @PathVariable("pageSize")Integer pageSize,
                                                   @RequestBody MsgParamVo msgParams){
        try {
            IPage<MsgResultVo> page=null;
            page = msgResultService.findMessages(pageNum,pageSize,msgParams);
            return Result.success(page);
        }catch (Exception e){
            log.error("===报警消息查询异常===",e);
            return Result.failure("报警消息查询异常");
        }
    }

    @ApiOperation("处理报警操作-支持批量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resultIds", value = "报警记录id",required = true, paramType = "query"),
            @ApiImplicitParam(name = "dealRemark", value = "处理描述", paramType = "query")
    })
    @GetMapping("/dealMeterResult")
    public Result dealMeterResult(@RequestParam(value = "resultIds") String resultIds ,
                                  @RequestParam(value = "dealRemark",required = false) String dealRemark ) {
        try {
            String [] Ids =resultIds.split(",");
            msgResultService.updateDealStateById(Ids,dealRemark);
            return   Result.success("处理成功");
        } catch (Exception e) {
            log.error("报警处理异常", e);
            return Result.failure("报警处理异常");
        }
    }
}
